from rest_framework.viewsets import ModelViewSet
from rest_framework import mixins
from . import models, serializers
from django.conf import settings
from rest_framework.response import Response
class BannerViewSet(ModelViewSet, mixins.ListModelMixin):
    queryset = models.Banner.objects.filter(is_delete=False, is_show=True).order_by('-orders')[:settings.BANNER_COUNT]
    serializer_class = serializers.BannerSerializer

    # 了解CORS本质，处理还是在中间件中用插件，因为可以控制所有接口
    """
    def list(self, request, *args, **kwargs):
        response = super().list(request, *args, **kwargs)
        # 响应头设置'Access-Control-Allow-Origin'为'*'就代表该接口可以对任何请求完成响应
        return Response(response.data, headers={'Access-Control-Allow-Origin': '*'})
    """


